home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / ViePratique / ArchiFacile / ArchiFacileSetup.exe / {app} / nw.pak / Unnamed File 001170.txt < prev    next >
Text File  |  2014-10-14  |  3KB  |  82 lines

  1. // Copyright (c) 2012 Intel Corp
  2. // Copyright (c) 2014 The Chromium Authors
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. //  in the Software without restriction, including without limitation the rights
  7. //  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
  8. // pies of the Software, and to permit persons to whom the Software is furnished
  9. //  to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in al
  12. // l copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
  15. // PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
  16. // S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  17. //  OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
  18. // ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. //  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20.  
  21. var screenInstance = null;
  22.  
  23. function Screen() {
  24.   nw.allocateObject(this, {});
  25.   this._numListener = 0;
  26. }
  27. require('util').inherits(Screen, exports.Base);
  28.  
  29. // Override the addListener method.
  30. Screen.prototype.on = Screen.prototype.addListener = function(ev, callback) {
  31.   if ( ev != "displayBoundsChanged" && ev != "displayAdded" && ev != "displayRemoved" )
  32.     throw new String('only following event can be listened: displayBoundsChanged, displayAdded, displayRemoved');
  33.   
  34.   var onRemoveListener = function (type, listener) {
  35.     if (this._numListener > 0) {
  36.       this._numListener--;
  37.       if (this._numListener == 0) {
  38.         process.EventEmitter.prototype.removeListener.apply(this, ["removeListener", onRemoveListener]);
  39.         nw.callStaticMethodSync('Screen', 'RemoveScreenChangeCallback', [ this.id ]);
  40.       }
  41.     }
  42.   };
  43.  
  44.   if(this._numListener == 0) {
  45.     if (nw.callStaticMethodSync('Screen', 'AddScreenChangeCallback', [ this.id ]) == false ) {
  46.       throw new String('nw.callStaticMethodSync(Screen, AddScreenChangeCallback) fails');
  47.       return;
  48.     }
  49.     process.EventEmitter.prototype.addListener.apply(this, ["removeListener", onRemoveListener]);
  50.   }
  51.   
  52.   // Call parent.
  53.   process.EventEmitter.prototype.addListener.apply(this, arguments);
  54.   this._numListener++;
  55. }
  56.  
  57. // Route events.
  58. Screen.prototype.handleEvent = function(ev) {
  59.   arguments[1] = JSON.parse(arguments[1]);
  60.   // Call parent.
  61.   this.emit.apply(this, arguments);
  62. }
  63.  
  64. Screen.prototype.__defineGetter__('screens', function() {
  65.   return JSON.parse(nw.callStaticMethodSync('Screen', 'GetScreens', [ ]));
  66. });
  67.  
  68.  
  69. // ======== Screen functions End ========
  70.  
  71. // Store App object in node's context.
  72. exports.Screen = {
  73. Init: function() {
  74.   if (screenInstance == null) {
  75.     screenInstance = new Screen();
  76.   }
  77.   exports.Screen = screenInstance;
  78.   return screenInstance;
  79. }
  80. };
  81.  
  82.